//
//  ZZDeviceCell.m
//  ZZBlue
//
//  Created by stonesMonkey on 2017/9/20.
//  Copyright © 2017年 stonesMonkey. All rights reserved.
//

#import "ZZDeviceCell.h"
#import "ZZDeviceModel.h"
#import "DeviceTool.h"

@interface ZZDeviceCell()

@property (weak, nonatomic) IBOutlet UILabel *deviceLable;

@property (weak, nonatomic) IBOutlet UIButton *openBtn;

@property (weak, nonatomic) IBOutlet UIImageView *connectImg;

@property (weak, nonatomic) IBOutlet UILabel *connectLabel;



@end

@implementation ZZDeviceCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)isOpen:(UIButton *)sender {
    
    sender.selected = !sender.selected;
    self.deviceModel.isClose = !sender.selected;

    if (self.colseClickBlock) {

        self.colseClickBlock(self.deviceModel.isClose,self.deviceModel);
    }
    
    [[DeviceTool new] save];
}


- (void)setDeviceModel:(ZZDeviceModel *)deviceModel {
    
    _deviceModel = deviceModel;
    
    self.deviceLable.text = deviceModel.deviceName;
    if (deviceModel.isConnect) {
        
        self.connectLabel.hidden = NO;
        self.connectImg.hidden = NO;
    } else{
        
        self.connectLabel.hidden = YES;
        self.connectImg.hidden = YES;
    }
    
    if (deviceModel.isClose) {
        
        self.openBtn.selected = NO; // 默认开启
    } else {
        
        self.openBtn.selected = YES;
    }
}

@end
